package com.sneaker.shower.controller;

import com.sneaker.shower.common.BaseView;
import com.sneaker.shower.entity.dto.DetailDTO;
import com.sneaker.shower.entity.dto.MenuDTO;
import com.sneaker.shower.entity.dto.MenuImageDTO;
import com.sneaker.shower.service.MainImageService;
import com.sneaker.shower.service.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/menu")
@Api("菜单相关API")
@Slf4j
public class MenuController {

    private final MenuService menuService;

    private final MainImageService mainImageService;

    @Autowired
    public MenuController(MenuService menuService,
                          MainImageService mainImageService) {
        this.menuService = menuService;
        this.mainImageService = mainImageService;
    }

    @GetMapping("/get")
    @ApiOperation("通过菜单guid 获取当前菜单及其子菜单和产品")
    public BaseView<MenuDTO> get(String menuGuid) {
        log.info("获取菜单请求入参：{}", menuGuid);
        return new BaseView<>(menuService.getMenu(menuGuid));
    }

    @GetMapping("/get_all")
    @ApiOperation("获取当前机构下的所有菜单及产品")
    public BaseView<List<MenuDTO>> getAll() {
        return new BaseView<>(menuService.getAll(null));
    }

    @GetMapping("/get_main_details")
    @ApiOperation("获取首页的产品详情相关")
    public BaseView<List<MenuImageDTO>> getMenuDetails() {
        return new BaseView<>(menuService.getMenuDetails());
    }

    @GetMapping("/get_main_image")
    @ApiOperation("获取首页的轮播图片地址")
    public BaseView<List<String>> getMainImage() {
        return new BaseView<>(mainImageService.getMainImages());
    }

    @GetMapping("/get_detail")
    public BaseView<DetailDTO> getDetail(@ApiParam(value = "产品类型，0：球鞋清洗， 1：球鞋修复") @RequestParam("type") Integer type,
                                         @ApiParam(value = "当前选择的guid，若不传，则认为是从快速通道进入，会返回快速通道的图")
                                         @RequestParam(value = "guid", required = false) Long guid) {
        log.info("详情请求参数：type:{}, guid:{}", type, guid);
        return new BaseView<>(menuService.getDetail(type, guid));
    }

    @PostMapping("/create/{orgGuid}")
    @ApiOperation("菜单创建接口，最外层menu需传入机构guid，入参需要从最外层的menu开始写")
    public BaseView create(@RequestBody MenuDTO menuDTO, @PathVariable("orgGuid") Long orgGuid) {
        menuService.create(menuDTO, orgGuid);
        return new BaseView();
    }

    @PostMapping("/create_main_image")
    public BaseView createImage(@RequestBody List<MenuImageDTO> menuImageDTOS) {
        menuService.createImage(menuImageDTOS);
        return new BaseView();
    }
}
